<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function arr(bills) {
      let five = 0, ten = 0;
      for (let i = 0; i < bills.length; i++) {
        if (bills[i] === 5) five++;
        else if (bills[i] === 10) {
          if (five === 0) return false;
          ten++;
          five--;
        } else if (five > 0 && ten > 0) {
          five--;
          ten--
        } else if (five >= 3) {
          five -= 3
        } else {
          return false
        }
      }

      return true
    };
    console.log(arr([5, 5, 5, 10, 20]));
  </script>
</body>

</html>